#include<cstdio>
using namespace std;
typedef long long ll;
ll f(int *p,int i,int final)
{
	if(i==0)return 0;
	if(p[i] == final)return f(p,i-1,final);
	return f(p,i-1,6-p[i]-final) + (1LL<<(i-1));
}
const int maxn = 70;
int n,start[maxn],finish[maxn];

int main()
{
	int kcase = 0;
	while(scanf("%d",&n)!=EOF)
	{
		if(n==0)return 0;
		for(int i=1;i<=n;i++)scanf("%d",start+i);
		for(int i=1;i<=n;i++)scanf("%d",finish+i);
		int k=n;
		while(k>=1 && start[k] == finish[k])k--;
		ll ans=0;
		if(k>=1)
		{
			ll other = 6-finish[k]-start[k];
			ans = f(start,k-1,other) + f(finish,k-1,other) + 1;
		}
		printf("Case %d: %lld\n",++kcase,ans);
	}
	return 0;
}